﻿namespace TravelPriceCalc
{
    class Program
    {
        const decimal OriginalPrice = 8800m;

        static void Main()
        {
            Console.WriteLine("=== 旅游价格计算器 ===");

            int month = ReadInt("请输入出行月份（1-12）：", 1, 12);
            char mode  = ReadChar("请选择交通方式：航班(F) 或 动车(D)：", new[] { 'F', 'f', 'D', 'd' });

            decimal discount = GetDiscount(month, char.ToUpper(mode));
            decimal price    = OriginalPrice * discount;

            Console.WriteLine($"折后价格为：{price:C2}");
            Console.WriteLine("按任意键退出...");
            Console.ReadKey();
        }

        
        private static decimal GetDiscount(int month, char mode)
        {
            bool isPeak = month >= 5 && month <= 10;
            return (mode, isPeak) switch
            {
                ('F', true)  => 0.90m,
                ('D', true)  => 0.75m,
                ('F', false) => 0.60m,
                ('D', false) => 0.30m,
                _ => throw new ArgumentException("无效交通方式")
            };
        }

        #region 简单输入校验辅助
        private static int ReadInt(string prompt, int min, int max)
        {
            int val;
            while (true)
            {
                Console.Write(prompt);
                if (int.TryParse(Console.ReadLine(), out val) && val >= min && val <= max)
                    return val;
                Console.WriteLine($"输入无效，请输入 {min} 到 {max} 之间的整数。");
            }
        }

        private static char ReadChar(string prompt, char[] valid)
        {
            char c;
            while (true)
            {
                Console.Write(prompt);
                var line = Console.ReadLine();
                if (line != null && line.Length == 1 && Array.Exists(valid, x => x == line[0]))
                    return line[0];
                Console.WriteLine("输入无效，请重新选择。");
            }
        }
        #endregion
    }
}
